#include "stdafx.h"

#include "database.h"
#include "adoadapter.h"
#include <iostream>

#import "msado15.dll" rename_namespace("") rename("EOF", "ADO_EOF") rename("BOF", "ADO_BOF")

int _tmain(int argc, _TCHAR* argv[])
{
  CPoolFactory * factory = new CADOPoolFactory;
  CPool * pool = factory->getPool();
  CResource * res = pool->aquire();

  _RecordsetPtr recordset;
	recordset.CreateInstance(__uuidof(Recordset));
	recordset->Open("SELECT TOP 10 * FROM JOURNALATTACHMENT", res->getConnectionVariant(), 
                  adOpenDynamic, adLockOptimistic, adCmdText);
  while (!recordset->ADO_EOF) {
    long mailId = (long)recordset->Fields->GetItem("MAILID")->Value;
		bstr_t name = (bstr_t)recordset->Fields->GetItem("ATTACHMENTNAME")->Value;
    std::cout << "mailId: " << mailId << " name: " << name << std::endl; 
    recordset->MoveNext();
  }
  recordset->Close();

  pool->release(res);
  res = NULL;
	return 0;
}

